﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace FYPDemo
{
    public class BackOffice_AdminLogin
    {
        public string checkAdmin(string username, string password)
        {
            string name = null;

            conndb con = new conndb();
            SqlConnection connection = con.GetOpenConnection();
            SqlCommand cmd = connection.CreateCommand();

            try
            {
                cmd.CommandText = "validateAdmin";
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add(new SqlParameter("@Username", SqlDbType.VarChar, 50));
                cmd.Parameters["@Username"].Value = username;

                cmd.Parameters.Add(new SqlParameter("@Password", SqlDbType.VarChar, 50));
                cmd.Parameters["@Password"].Value = password;

                SqlDataReader dtr = cmd.ExecuteReader();
                DataTable dt = new DataTable();

                if (dtr.HasRows)
                    dt.Load(dtr);
                else
                    dt = null;

                name = dt.Rows[0][0].ToString();

                connection.Close();
            }

            catch (Exception ex)
            {
                connection.Close();
                throw ex;
            }

            finally
            {
                if (connection != null)
                { connection.Close(); }
            }


            return name;
        }
    }
}